package org.biloxi.commands.draw;
import org.biloxi.commands.CommandRepository;
import org.biloxi.commands.impl.CommandImpl;
import org.biloxi.commands.movecard.MoveCard;
import org.biloxi.model.magicobjects.MagicObject;
import org.biloxi.model.mutable.GameStateMutable;
import org.biloxi.model.player.PlayerState;
import org.biloxi.model.player.Zone;
import org.biloxi.player.PlayerID;

public class Draw extends CommandImpl<Draw.Options, Draw.Result> {
	static public class Options {
		public final PlayerID pid;
		public Options(PlayerID pid) {
			this.pid = pid;
		}
	}
	static public class Result {
		public final PlayerID pid;
		public final Zone source;
		public final MagicObject card;
		public Result(PlayerID pid, Zone source, MagicObject card) {
			this.pid = pid;
			this.source = source;
			this.card = card;
		}
	}
	
	public Draw(CommandRepository cr) {
		super(cr);
	}

	@Override
	protected Result executeImpl(Options o, GameStateMutable gameState) {
		PlayerState p = gameState.getPlayerState(o.pid);

		if (p.getLibrary().getMagicObjects().size() > 0) {
			MagicObject card = p.getLibrary().getMagicObjects().get(0);
			
			MoveCard.Result tmpResult = c.moveCard( new MoveCard.Options(p.getLibrary(), p.getHand(),card) );
			return new Result(tmpResult.dest.getOwnerid(), tmpResult.source,
					tmpResult.card);
		} else {
			return new Result(o.pid, null, null);
		}
	}

}
